package com.workplan.client.widgets.createemployee;

import com.general.client.action.ActionHandler;
import com.general.client.basewidget.BaseWidget;
import com.general.client.position.Position;
import com.general.client.widgets.button.green.GreenButton;
import com.general.client.widgets.combobox.Combobox;
import com.general.client.widgets.textbox.TextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Widget;
import com.workplan.shared.datamodel.employee.EmployeeDataModel.Role;

public class CreateEmployee extends BaseWidget implements
		CreateEmployeePresenter.Display {

	private static CreateEmployeeUiBinder uiBinder = GWT
			.create(CreateEmployeeUiBinder.class);

	interface CreateEmployeeUiBinder extends UiBinder<Widget, CreateEmployee> {
	}

	@UiField
	TextBox firstName;
	@UiField
	TextBox lastName;
	@UiField
	TextBox phoneNumber;
	@UiField
	TextBox email;
	@UiField
	Combobox<Integer> minShifts;
	@UiField
	Combobox<Integer> maxShifts;
	@UiField
	Combobox<Role> role;

	@UiField
	GreenButton addButton;

	public CreateEmployee() {
		initWidget(uiBinder.createAndBindUi(this));
		addButton.getText().setText("Add");

		firstName.setLabel("First Name");
		firstName.setLabelPosition(Position.ABOVE);
		firstName.setMandatory(true);
		lastName.setLabel("Last Name");
		lastName.setLabelPosition(Position.ABOVE);
		lastName.setMandatory(true);
		phoneNumber.setLabel("Phone #");
		phoneNumber.setLabelPosition(Position.ABOVE);
		email.setLabel("E-Mail");
		email.setLabelPosition(Position.ABOVE);
		minShifts.setLabel("Min. Shifts");
		minShifts.setLabelPosition(Position.ABOVE);
		for (Integer i = 0; i <= 7; i++) {
			minShifts.addItem(i, i.toString());
		}
		maxShifts.setLabel("Max. Shifts");
		maxShifts.setLabelPosition(Position.ABOVE);
		for (Integer i = 0; i <= 7; i++) {
			maxShifts.addItem(i, i.toString());
		}
		role.setLabel("Position");
		role.setLabelPosition(Position.ABOVE);
		role.addItem(Role.EMPLOYEE, "Employee");
		role.addItem(Role.SHIFT_MANAGER, "Shift Manager");
		role.addItem(Role.MANAGER, "Manager");
		role.setMandatory(true);

	}

	@Override
	public TextBox getFirstName() {
		return firstName;
	}

	@Override
	public TextBox getLastName() {
		return lastName;
	}

	@Override
	public TextBox getPhoneNumber() {
		return phoneNumber;
	}

	@Override
	public TextBox getEmail() {
		return email;
	}

	@Override
	public Combobox<Integer> getMinShifts() {
		return minShifts;
	}

	@Override
	public Combobox<Integer> getMaxShifts() {
		return maxShifts;
	}

	@Override
	public Combobox<Role> getRole() {
		return role;
	}

	@Override
	public HandlerRegistration addAddActionHandler(ActionHandler handler) {
		return addButton.addActionHandler(handler);
	}

	@Override
	public boolean isValid() {
		return (firstName.isValid() && lastName.isValid() && role.isValid());
	}

	@Override
	public void clear() {
		firstName.setValue(null);
		lastName.setValue(null);
		email.setValue(null);
		phoneNumber.setValue(null);
		minShifts.setValue(null);
		maxShifts.setValue(null);
		role.setValue(null);
	}

}
